//package com.fingard.dsp.bank.directbank.ccb04;
//
//import com.fingard.FGBiz;
//import com.fingard.constant.Format;
//import com.fingard.dsp.DSPSet;
//import com.fingard.dsp.bank.dbobj.receipt.ReceiptMapping;
//import com.fingard.dsp.bank.directConfig.FtpSet;
//import com.fingard.dsp.bank.directbank.bankInterface.IReceipt;
//import com.fingard.dsp.bank.directbank.ccb04.util.Des3;
//import com.fingard.dsp.bank.directbank.ccb04.util.RSAHelper;
//import com.fingard.dsp.bank.helpers.HelperResp;
//import com.fingard.dsp.bank.helpers.ReceiptFileSaveHelper;
//import com.fingard.dsp.bank.reqrespobj.downloadreceipt.ReqQryReceipt;
//import com.fingard.dsp.bank.reqrespobj.downloadreceipt.RetAtsReceipt;
//import com.fingard.dsp.bank.reqrespobj.transaction.Req7516HisTrans;
//import com.fingard.io.FileHelper;
//import com.fingard.net.ConnState;
//import com.fingard.net.FtpReceiver;
//import com.fingard.net.SftpPortClient;
//import com.fingard.text.Base64Helper;
//import com.fingard.text.StringHelper;
//import com.fingard.util.SmbFileUtil;
//import com.fingard.xml.XElement;
//import com.fingard.xml.XmlTextReader;
//import com.fingard.xml.XmlTextWriter;
//import org.bouncycastle.util.encoders.Base64;
//
//import java.io.BufferedOutputStream;
//import java.io.File;
//import java.io.FileOutputStream;
//import java.io.IOException;
//import java.net.URLEncoder;
//import java.text.SimpleDateFormat;
//import java.util.*;
//import java.util.concurrent.Executor;
//import java.util.concurrent.Executors;
//
///**
// * @author Cruise on
// * @date 2019/7/10
// */
//public class CCB04Receipt extends CCB04Base implements IReceipt, Runnable {
//    //是否已经在运行推送任务了
//    private boolean isWorking = false;
//    //第一遍推送完是否需要再次推送
//    private boolean isAddition = false;
//
//    @Override
//    public RetAtsReceipt qryReceipt(ReqQryReceipt p_reqReceipt) throws Exception {
//        RetAtsReceipt retAts = new RetAtsReceipt(p_reqReceipt.reqHeader);
//        CCB04Transaction transaction = new CCB04Transaction();
//        transaction.CCBS_TxnSrlNos = this.CCBS_TxnSrlNos;
//        transaction.reqHeader = p_reqReceipt.reqHeader;
//        transaction.bankFront = this.bankFront;
//        transaction.sbLog = this.sbLog;
//        p_reqReceipt.reqHeader.transType = "7516";
//        Req7516HisTrans tmpReq7516 = new Req7516HisTrans(p_reqReceipt.reqHeader);
//        tmpReq7516.actArea = p_reqReceipt.areaCode;
//        tmpReq7516.actCur = p_reqReceipt.actCur;
//        tmpReq7516.actNum = p_reqReceipt.actNum;
//        tmpReq7516.dateFrom = p_reqReceipt.dateFrom;
//        tmpReq7516.dateTo = p_reqReceipt.dateTo;
//        tmpReq7516.directRight = p_reqReceipt.directRight;
//        //指明是回单查询发起的历史明细查询
//        transaction.isFromReceiptQry = true;
//        //调用历史明细查询 接口查询CCBS交易流水号
//        transaction.d_7516_HisTrans(tmpReq7516);
//
//        Iterator<Map.Entry<String, String>> entries = transaction.CCBS_TxnSrlNos.entrySet().iterator();
//        while(entries.hasNext()){
//            Map.Entry<String, String> entry = entries.next();
//            String key = entry.getKey();
//            String value = entry.getValue();
//            WriteBankLogLn("当前CCBS_TxnSrlNos中'receiptNo'值为:" + key + ",'askNumber'值为:" + value);
//        }
//        p_reqReceipt.reqHeader.transType = "DOWNLOADRECEIPT";
//        String tmpRespCode = "";
//        StringBuilder tmpRespInfo = new StringBuilder();
//        //查询回单索引 P1CCMS001
//
//        page = "1";
//        //回单编号-->CCBS流水号|交易日期
//        for (Map.Entry<String, String> map : CCBS_TxnSrlNos.entrySet()) {
//            txCode = "P1CCMS001";
//            Map<String, String[]> innerNos = new HashMap<String, String[]>();
//            XmlTextWriter xmlWriterWithoutCDATA = new XmlTextWriter();//发银行报文的XML对象
//            writeCommonHeaderWithoutCDATA(xmlWriterWithoutCDATA);
//            xmlWriterWithoutCDATA.writeStartElement("request");
//            xmlWriterWithoutCDATA.writeElementString("ACCT_NO", p_reqReceipt.actNum);
//            xmlWriterWithoutCDATA.writeElementString("TX_LOG_NO", map.getKey());
//            xmlWriterWithoutCDATA.writeElementString("BEGIN_DATE", Format.Date8Format.format(p_reqReceipt.getDateFrom()));
//            xmlWriterWithoutCDATA.writeElementString("END_DATE", Format.Date8Format.format(p_reqReceipt.getDateTo()));
//            xmlWriterWithoutCDATA.writeElementString("MIN_AMT ", "", true);
//            xmlWriterWithoutCDATA.writeElementString("MAX_AMT", "", true);
//            xmlWriterWithoutCDATA.writeElementString("PATCH_FLAG", "", true);
//            xmlWriterWithoutCDATA.writeElementString("DOC_NO", "", true);
//            xmlWriterWithoutCDATA.writeElementString("PAGE_NO", String.valueOf(page));
//            xmlWriterWithoutCDATA.writeElementString("INQUIRE_NUM", "10");
//            xmlWriterWithoutCDATA.writeElementString("ASPD_ECD", "00000886");
//            xmlWriterWithoutCDATA.writeEndDocument();
//            int n = xmlWriterWithoutCDATA.toXmlString().length();
//            WriteBankLogLn("无CDATA:\n" + xmlWriterWithoutCDATA.toXmlString());
//            xmlLength = decimalFormat.format(n);
//            XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
//            //写入通用的头部节点
//            writeCommonHeader(xmlWriter);
//            xmlWriter.writeStartElement("request");
//            xmlWriter.writeElementCDATA("ACCT_NO", p_reqReceipt.actNum);
//            xmlWriter.writeElementCDATA("TX_LOG_NO", map.getKey());
//            xmlWriter.writeElementCDATA("BEGIN_DATE", Format.Date8Format.format(p_reqReceipt.getDateFrom()));
//            xmlWriter.writeElementCDATA("END_DATE", Format.Date8Format.format(p_reqReceipt.getDateTo()));
//            xmlWriter.writeElementCDATA("MIN_AMT ", "");
//            xmlWriter.writeElementCDATA("MAX_AMT", "");
//            xmlWriter.writeElementCDATA("PATCH_FLAG", "");
//            xmlWriter.writeElementCDATA("DOC_NO", "");
//            xmlWriter.writeElementCDATA("PAGE_NO", String.valueOf(page));
//            xmlWriter.writeElementCDATA("INQUIRE_NUM", "10");
//            xmlWriter.writeElementCDATA("ASPD_ECD", "00000886");
//            xmlWriter.writeEndDocument();
//            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
//            StringBuilder msg = new StringBuilder();
//            XmlTextReader tmpBkReader = null;
//            try {
//                tmpBkReader = getBankInfo(tmpStrRet[1], msg);
//                if (tmpBkReader != null) {
//                    String xlnStatus = tmpBkReader.getFirstText("/Transaction/Transaction_Header/SYS_TX_STATUS"); // 服务状态
//                    String xlnRespCode = tmpBkReader.getFirstText("/Transaction/Transaction_Body/response/RESP_CODE"); // 服务响应码
//                    String xlnRespDesc = tmpBkReader.getFirstText("/Transaction/Transaction_Body/response/RESP_MESG"); // 服务响应描述
//                    if (IsResultInvlid(tmpStrRet[1], tmpBkReader, false, retAts)) {
//                        if (tmpStrRet[0].length() == 0) {
//                            if ("000000".equals(xlnRespCode)) {
//                                while (tmpBkReader.read("/Transaction/Transaction_Body/response/Record")) {
//                                    String busRef = tmpBkReader.readedXElement.getSingleText("INNER_NO");
//                                    String receipNo = map.getKey();
//                                    String transdate = tmpBkReader.readedXElement.getSingleText("TRAN_DATE");
//                                    String oppActName = URLEncoder.encode(tmpBkReader.readedXElement.getSingleText("OP_ACCT_NAME"), "GBK");
//                                    String oppActNum = tmpBkReader.readedXElement.getSingleText("OP_ACCT_NO");
//                                    String amount = tmpBkReader.readedXElement.getSingleText("TX_AMT");
//                                    String currName = tmpBkReader.readedXElement.getSingleText("CURR_NAME");
//                                    String tranSeqNo = tmpBkReader.readedXElement.getSingleText("LOG_NO");
//                                    String moneyway = tmpBkReader.readedXElement.getSingleText("CR_COD");
//                                    String receipType = tmpBkReader.readedXElement.getSingleText("DOC_TYP");
//                                    innerNos.put(busRef, new String[]{receipNo, transdate, oppActName, oppActNum, amount, currName, tranSeqNo, moneyway, receipType});
//                                }
//                                if (innerNos.isEmpty()) {
//                                    continue;
//                                }
//                            } else {
//                                tmpRespCode = "-1";
//                                tmpRespInfo.append(xlnStatus).append(xlnRespCode).append(xlnRespDesc).append("\n");
//                            }
//                        } else {
//                            tmpRespCode = "-1";
//                            tmpRespInfo.append(tmpStrRet[1]).append("\n");
//                        }
//                    } else {
//                        tmpRespCode = "-1";
//                        tmpRespInfo = tmpRespInfo.append(xlnStatus).append(xlnRespCode).append(xlnRespDesc);
//                    }
//                } else {
//                    tmpRespCode = "-1";
//                    tmpRespInfo.append(msg.toString()).append("\n");
//                }
//            } catch (Exception e) {
//                WriteBankLogLn(e);
//                continue;
//            }
//
//            txCode = "P1CCMS006";
//            page = "1";
//            //回单编号-->CCBS流水号|交易日期
//            for (Map.Entry<String, String[]> innerNo : innerNos.entrySet()) {
//                //根据索引号下载电子回单
//                List<String> filenames = new ArrayList<String>();
//                //返回到ATS的请求String
//                StringBuilder json = new StringBuilder();
//                if(getBankConfig().getValueAsBool("receiptPushHasTenantId")){
//                    json.append("tenantId="+FGBiz.dspCenter.dspSet.tenant+"&transType=downloadreceipt&data={\"rows\":[");
//                }else{
//                    json.append("transType=downloadreceipt&data={\"rows\":[");
//                }
//                int tmpFileCount = 0;//记录上传成功的回单数
//                StringBuilder sb = new StringBuilder();
//                //发银行报文的XML对象
//                xmlWriterWithoutCDATA = new XmlTextWriter();
//                writeCommonHeaderWithoutCDATA(xmlWriterWithoutCDATA);
//                xmlWriterWithoutCDATA.writeStartElement("request");
//                xmlWriterWithoutCDATA.writeElementString("ACCT_NO", p_reqReceipt.actNum);
//                xmlWriterWithoutCDATA.writeElementString("DOWNLOAD_NOS", innerNo.getKey());
//                xmlWriterWithoutCDATA.writeElementString("ASPD_ECD", "00000886");
//                xmlWriterWithoutCDATA.writeEndDocument();
//                n = xmlWriterWithoutCDATA.toXmlString().length();
//                xmlLength = decimalFormat.format(n);
//                xmlWriter = new XmlTextWriter();//发银行报文的XML对象
//                //写入通用的头部节点
//                writeCommonHeader(xmlWriter);
//                xmlWriter.writeStartElement("request");
//                xmlWriter.writeElementCDATA("ACCT_NO", p_reqReceipt.actNum);
//                xmlWriter.writeElementCDATA("DOWNLOAD_NOS", innerNo.getKey());
//                xmlWriter.writeElementCDATA("ASPD_ECD", "00000886");
//                xmlWriter.writeEndDocument();
//                tmpStrRet = sendToBank(xmlWriter.toXmlString());
//                msg = new StringBuilder();
//                try {
//                    tmpBkReader = getBankInfo(tmpStrRet[1], msg);
//                    if (tmpBkReader != null) {
//                        String xlnStatus = tmpBkReader.getFirstText("/Transaction/Transaction_Header/SYS_TX_STATUS"); // 服务状态
//                        String xlnRespCode = tmpBkReader.getFirstText("/Transaction/Transaction_Header/SYS_RESP_CODE"); // 服务响应码
//                        String xlnRespDesc = tmpBkReader.getFirstText("/Transaction/Transaction_Header/SYS_RESP_DESC"); // 服务响应描述
//                        if (tmpStrRet[0].length() == 0) {
//                            if ("000000000000".equals(xlnRespCode)) {
//                                while (tmpBkReader.read("/Transaction/Transaction_Body/response/FILE_LIST_PACK")) {
//                                    List<XElement> fileinfos = tmpBkReader.readedXElement.getChildList("FILE_INFO");
//                                    for (XElement xElement : fileinfos) {
//                                        filenames.add(xElement.getSingleText("FILE_NAME"));
//                                    }
//                                }
//                            } else {
//                                tmpRespCode = "-1";
//                                tmpRespInfo.append(xlnStatus).append(xlnRespCode).append(xlnRespDesc);
//                            }
//                        } else {
//                            tmpRespCode = "-1";
//                            tmpRespInfo.append(tmpStrRet[1]);
//                        }
//                    } else {
//                        tmpRespCode = "-1";
//                        tmpRespInfo.append(msg.toString());
//                    }
//                } catch (Exception e) {
//                    WriteBankLogLn(e);
//                    continue;
//                }
//                ReceiptFileSaveHelper saveHelper = null;
//                if (filenames.size() > 0) {
//                    tmpRespCode = "0";
//                    if (saveHelper == null) {
//                        saveHelper = new ReceiptFileSaveHelper(this);
//                    }
//                }
//
//                for (int x = 0; x < filenames.size(); x++) {
//                    try {
//                        //POST 参数 1: chanl_cust_no=电子银行合约编号
//                        String chanl_cust_no = bankFront.org;
//                        byte[] tmpName = Des3.encryptMode(Base64Helper.decode(bankFront.token), filenames.get(x).getBytes("GBK"));
//                        tmpName = Base64.encode(tmpName);
//                        String filename = new String(tmpName);
//                        //POST 参数 3：signature=数字签名（对文件名作的数字签名）
//                        String priKey = FileHelper.readFileText(strtmpFile + chanl_cust_no + "_prikey.txt", getCharset());
//                        //MD5withRSA(batchFileName);
//                        String signature = RSAHelper.sign(new String(filenames.get(x)), priKey, getCharset());
//                        StringBuilder tmpMsg = new StringBuilder();
//                        tmpMsg.append("chanl_cust_no=" + URLEncoder.encode(chanl_cust_no, "gbk"));
//                        tmpMsg.append("&filename=" + URLEncoder.encode(filename, "gbk"));
//                        tmpMsg.append("&signature=" + URLEncoder.encode(signature, "gbk"));
//                        String[] postRet = download(tmpMsg.toString());
//                        String batchResult = "";
//                        boolean isFile = false;
//                        try {
//                            batchResult = IsBatchValid(postRet[1]);
//                        } catch (NumberFormatException e) {
//                            isFile = true;
//                        }
//                        if (isFile) {
//                            byte[] tmpBNKReturnBytes = null;
//                            //得到银行返回的数字签名Md5_byte和报文密文DES_byte
//                            //HTTP 服务方返回时是返回一个字节流 byte[]，因此需要约定 byte[]的数据格式。
//                            //返回的 byte[]的格式：数字签名的长度(固定长度 10 个字节) +数字签名数据+加密后的数据。解密时应先根据前 10 位算出数字签名的长度，然后再截取数字签名及报文密文。
//                            byte[] data = base64Decoder.decodeBuffer(postRet[1]);
//                            byte[] p_Key = Base64Helper.decode(bankFront.token);
//                            //Todo
//                            tmpBNKReturnBytes = Des3.decryptMode(p_Key, data);
//                            //回单编号
//                            String receiptno = innerNo.getKey();
//                            String transdate = innerNo.getValue()[1];
//                            String tmpLOG_NO = innerNo.getValue()[6];
//                            //资金上传文件到共享目录（默认不开启）
//                            if (this.getBankConfig().getValueAsBool("receiptUploadShared")) {
//                                String qjlocalPath = bankFront.bankReceiptMainDir + File.separator + "CCB04" + File.separator + transdate.substring(0, 8) + File.separator + p_reqReceipt.actNum;
//                                qjlocalPath = DSPSet.replaceFilePath(qjlocalPath);
//                                if (qjlocalPath != null && tmpBNKReturnBytes != null) {
//                                    FileOutputStream fos = null;
//                                    BufferedOutputStream bfo = null;
//                                    try {
//                                        String localFile = qjlocalPath + File.separator + receiptno + ".pdf";
//                                        File file = new File(localFile);
//                                        if (!file.exists()) {
//                                            if (!file.getParentFile().exists()) {
//                                                file.getParentFile().mkdirs();
//                                            }
//                                            file.createNewFile();
//                                        }
//                                        fos = new FileOutputStream(file);
//                                        bfo = new BufferedOutputStream(fos);
//                                        bfo.write(tmpBNKReturnBytes, 0, tmpBNKReturnBytes.length);
//                                        bfo.flush();
//
//                                        bfo.close();
//                                        fos.close();
//                                        tmpRespInfo.append("成功下载电子回单:").append(localFile).append("\n");
//                                        //DSP获取回单后，上传共享目录
//                                        if (file != null) {
//                                            //回单存放共享目录路径
//                                            String tmpByDate = Format.Date8Format.format(new Date());
//                                            tmpByDate = tmpByDate.substring(0, 6) + "/" + tmpByDate.substring(6, 8) + "/" + reqHeader.bankCode + "/" + p_reqReceipt.actNum + "/";
//                                            //2.3.1、上传文件到共享目录下
//                                            int result = -1;
//                                            WriteBankLogLn("正在上传文件至共享目录:" + FGBiz.dspCenter.dspSet.receiptShareDir);
//                                            if (file.exists()) {
//                                                result = SmbFileUtil.smbUploading(file.getPath(), tmpByDate, FGBiz.dspCenter.dspSet.receiptShareDir);
//                                            }
//                                            //2.3.2、上传成功处理
//                                            if (result == 0 || result == 1) {
//                                                //记录上传成功数
//
//                                                if (result == 0) {
//                                                    WriteBankLogLn("文件上传成功");
//                                                } else {
//                                                    WriteBankLogLn("文件已存在共享目录无需重复上传");
//                                                }
//                                                //推送数据给ATS处理
//                                                String moneyway = innerNo.getValue()[7].equals("借") ? "1" : "2";
//                                                json.append("{");
//                                                json.append("\"actNum\":\"" + p_reqReceipt.actNum + "\",");
//                                                json.append("\"actCur\":\"" + convertCurToATS(innerNo.getValue()[5]) + "\",");
//                                                json.append("\"receiptCode\":\"" + receiptno + "\",");//回单编号
//                                                json.append("\"receiptType\":\"" + "" + "\",");//回单类型  1：存款回单；2：取款回单；3：转账回单；4：缴税回单；5：收费回单；6定期回单；7：活期回单
//                                                json.append("\"receiptState\":\"" + "" + "\",");//回单状态 1：正常；2：冲正；3：被冲正；4：当日冲正
//                                                json.append("\"oppActName\":\"" + innerNo.getValue()[2] + "\",");
//                                                json.append("\"oppActNum\":\"" + innerNo.getValue()[3] + "\",");
//                                                json.append("\"amount\":\"" + innerNo.getValue()[4] + "\",");
//                                                json.append("\"moneyway\":\"" + moneyway + "\",");
//                                                json.append("\"tranSeqNo\":\"" + innerNo.getValue()[6] + "\",");
//                                                json.append("\"tranCode\":\"" + "" + "\",");//交易码
//                                                json.append("\"tranDate\":\"" + Format.Date10Format.format(Format.Date8Format.parse(transdate)) + "\",");
//                                                json.append("\"filePath\":\"" + tmpByDate + file.getName() + "\",");//回单文件仓库存储路径
//                                                json.append("\"fileType\":\"1\"");
//                                                json.append("},");
//                                                sb.append(file.getName() + ",");
//                                                tmpFileCount++;
//                                                //文件处理完毕，删除临时文件
//                                                if (FileHelper.deleteFileIfExists(file.getPath())) {
//                                                    WriteBankLogLn("已删除临时文件：" + file.getPath());
//                                                }
//                                                WriteBankLogLn("推送给ATS的数据" + json);
//                                            } else {
//                                                WriteBankLogLn("上传文件至共享目录失败，请检查共享目录配置是否正确");
//                                                continue;
//                                            }
//                                        }
//                                    } catch (IOException e) {
//                                        WriteBankLogLn(e);
//                                    } finally {
//                                        if (bfo != null) {
//                                            try {
//                                                bfo.close();
//                                            } catch (Exception e) {
//
//                                            }
//                                        }
//                                        if (fos != null) {
//                                            try {
//                                                fos.close();
//                                            } catch (Exception e) {
//
//                                            }
//                                        }
//
//                                    }
//                                }
//                            } else {
//                                //本地回单路径
//                                //      //与资金约定写入回单相对路径为：/银行代码/YYYYMM/付方账号/回单编号.pdf；举例如： CCB/201812/123456/17213000001.pdf
//                                String localPath = bankFront.bankReceiptMainDir + File.separator + "CCB" + File.separator + transdate.substring(0, 6) + File.separator + p_reqReceipt.actNum;
//                                localPath = DSPSet.replaceFilePath(localPath);
//                                if (localPath != null && tmpBNKReturnBytes != null) {
//                                    FileOutputStream fos = null;
//                                    BufferedOutputStream bfo = null;
//                                    try {
//                                    	//receiptno
//                                        String localFile = localPath + File.separator + tmpLOG_NO + ".pdf";
//                                        File file = new File(localFile);
//                                        if (!file.exists()) {
//                                            if (!file.getParentFile().exists()) {
//                                                file.getParentFile().mkdirs();
//                                            }
//                                            file.createNewFile();
//                                        }
//                                        fos = new FileOutputStream(file);
//                                        bfo = new BufferedOutputStream(fos);
//                                        bfo.write(tmpBNKReturnBytes, 0, tmpBNKReturnBytes.length);
//                                        bfo.flush();
//
//                                        tmpRespInfo.append("成功下载电子回单:").append(localFile).append("\n");
//                                        //DSP获取回单后，通过sftp方式推送到指定的文件服务器；
//                                        ReceiptMapping eachRcptMp = new ReceiptMapping();
//                                        eachRcptMp.bank = "105";
//                                        eachRcptMp.busDate = Integer.parseInt(transdate);
//                                        eachRcptMp.ownAct = p_reqReceipt.actNum;
//                                        eachRcptMp.askNumber = map.getValue();
//                                        eachRcptMp.keyName = "receiptNo";
//                                        eachRcptMp.receiptNo = map.getKey();
//                                        eachRcptMp.busRef = tmpLOG_NO;
//                                        eachRcptMp.srcFile = StringHelper.getFileName(localFile);
//                                        WriteBankLogLn("当前ReceiptMapping中'askNumber'值为:" + eachRcptMp.askNumber + ",'receiptNo'值为:" + eachRcptMp.receiptNo);
//                                        HelperResp saveResp = saveHelper.saveByRcptMap(reqHeader, eachRcptMp, localFile);
//                                        WriteBankLogLn(saveResp.sbMsg);
//                                        if (saveResp.isCompleted) {
//                                            WriteBankLogLn(receiptno + "回单文件保存HTTP服务器成功");
//                                        } else if (ConnState.FAIL.equals(saveResp.connState)) {
//                                            WriteBankLogLn("连接服务器失败:" + saveResp.connState);
//                                            tmpRespCode = "-1";
//                                            break;
//                                        } else if (ConnState.CLASS_NOT_FOUND.equals(saveResp.connState)) {
//                                            WriteBankLogLn(ConnState.CLASS_NOT_FOUND + "初始化类异常，终止本次推送");
//                                            tmpRespCode = "-1";
//                                            break;
//                                        }
//                                    } catch (IOException e) {
//                                        WriteBankLogLn(e);
//                                    } finally {
//                                        if (fos != null) {
//                                            try {
//                                                fos.close();
//                                            } catch (Exception e) {
//
//                                            }
//                                        }
//                                        if (bfo != null) {
//                                            try {
//                                                bfo.close();
//                                            } catch (Exception e) {
//
//                                            }
//                                        }
//                                    }
//                                }
//                            }
//                        } else {
//                            tmpRespInfo.append(batchResult.split("\\|")[2]).append("\n");
//                        }
//                    } catch (Exception e) {
//                        WriteBankLogLn(e);
//                    }
//                }
//                if (this.getBankConfig().getValueAsBool("receiptUploadShared")) {
//                    WriteBankLogLn("成功保存了" + tmpFileCount + "个文件,文件名为：" + sb);
//                    //3、上传共享目录成功数据推送到ats
//                    if (tmpFileCount > 0) {
//                        json.deleteCharAt(json.length() - 1);
//                        json.append("]}");
//                        WriteBankLogLn("推送数据到ATS的数据为：" + json.toString());
//                        String[] data = sendToATS(json.toString());
//                        if (data[0].length() == 0 && data[1].equals("ok")) {
//                            WriteBankLogLn("推送数据到ATS成功,请查看数据");
//                        } else {
//                            WriteBankLogLn("推送数据到ATS失败");
//                        }
//                    } else {
//                        WriteBankLogLn("成功保存文件条数为0，不需要推送数据到ATS");
//                    }
//                }
//            }
//        }
//        if ("".equals(tmpRespCode)) {
//            tmpRespCode = "0";
//        }
//        retAts.respCode = tmpRespCode;
//        if ("".equals(tmpRespInfo)) {
//            tmpRespInfo.append("无回单数据");
//        }
//        retAts.respInfo = tmpRespInfo.toString();
//        retAts.writeRetToATS();
//        if (getBankConfig().getValueAsBool("isPushReceipt")) {
//            Executor e = Executors.newScheduledThreadPool(1);
//            e.execute(this);
//            WriteBankLogLn("开始通过SFTP上送电子回单");
//        }
//        return retAts;
//    }
//
//    void pushReceipt() {
//        SftpPortClient sftpPortClient = null;
//
//        try {
//
//        	FtpSet ftpSet = bankFront.getFtpSet("receipt");
//        	sftpPortClient = new SftpPortClient(ftpSet);
//
//            StringBuilder sb = new StringBuilder();
//            SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
//            if (!isWorking) {
//                isWorking = true;
//                List<String> delList = new ArrayList<String>();
//
//                String localPath = DSPSet.replaceFilePath(bankFront.bankReceiptMainDir);
//                do {
//                    isAddition = false;
//                    localPath = localPath + File.separator + "CCB" + File.separator;
//                    String[] transdates = FileHelper.listFiles(localPath);
//                    if (transdates != null) {
//
//                        sb.append(sdf.format(System.currentTimeMillis()) + "    " + "开始遍历" + localPath + "上送文件至" + ftpSet.serverIP + ":" + ftpSet.port + "\n");
//
//
//                        for (String transdate : transdates) {
//                            String actPath = localPath + transdate;
//                            if (!new File(actPath).isDirectory()) {
//                                continue;
//                            }
//                            String[] actNums = FileHelper.listFiles(actPath);
//                            if (actNums == null) {
//                                continue;
//                            }
//                            for (String actNum : actNums) {
//                                String filePath = actPath + File.separator + actNum;
//                                sb.append(sdf.format(System.currentTimeMillis()) + "    " + "开始遍历文件夹" + filePath + "\n");
//                                File fileDir = new File(filePath);
//                                File[] files = fileDir.listFiles();
//                                if (files == null) {
//                                    continue;
//                                }
//                                for (File file : files) {
//                                    if (!file.isFile() || file.length() == 0) {
//                                        continue;
//                                    }
//
//                                    //与资金约定写入回单相对路径为：/银行代码/YYYYMM/付方账号/回单编号.pdf；举例如： CCB/201812/123456/17213000001.pdf
//                                    StringBuilder pathSb = new StringBuilder(ftpSet.getUpDir("receipt"));
//                                    pathSb.append("CCB/").append(transdate, 0, 6).append("/").append(actNum);
//                                    ftpSet.upDir = pathSb.toString();
//                                    sb.append(sdf.format(System.currentTimeMillis()) + "    " + "SFTP服务器文件路径:" + ftpSet.upDir + "\n");
//                                    FtpReceiver ftpReceiver = null;
//                                    ftpReceiver = sftpPortClient.uploadFile("", file.getAbsolutePath(), file.getName());
//                                    if (ftpReceiver.isCompleted) {
//                                        sb.append("电子回单文件：" + file.getAbsolutePath() + "推送成功");
//                                        delList.add(file.getAbsolutePath());
//                                    } else if (ConnState.FAIL.equals(ftpReceiver.connState)) {
//                                        sb.append(sdf.format(System.currentTimeMillis()) + "  " + ftpReceiver.connState + ":" + ftpReceiver.connMsg + ",电子回单文件：" + file.getAbsolutePath() + "推送失败" + "\n");
//                                    } else {
//                                        sb.append(sdf.format(System.currentTimeMillis()) + "  " + ftpReceiver.connState + ":" + ftpReceiver.connMsg + ",电子回单文件：" + file.getAbsolutePath() + "推送失败" + "\n");
//                                    }
//                                }
//                            }
//                        }
//                    }
//                } while (isAddition);
//
//                //传送完成删除本地文件
//                sb.append(sdf.format(System.currentTimeMillis()) + "  " + "开始删除本地文件" + "\n\n");
//                for (String delFile : delList) {
//                    File file = new File(delFile);
//                    if (file.exists() && file.isFile()) {
//                        if (file.delete()) {
//                            sb.append(sdf.format(System.currentTimeMillis()) + "  " + file.getAbsolutePath() + " 删除成功" + "\n");
//                        } else {
//                            sb.append(sdf.format(System.currentTimeMillis()) + "  " + file.getAbsolutePath() + " 删除失败" + "\n");
//                        }
//                    }
//
//                }
//            } else {
//                isAddition = true;
//            }
//            String tmpDateDir = Format.DateForLogFormat.format(new Date()).replace("-", File.separator);
//            String tmpSubFileName = FGBiz.dspCenter.bankLogsFirstDir + File.separator + tmpDateDir + File.separator + bankFront.bankCode + File.separator + "CCB04_UploadLog_" + Format.DateTime14Format.format(new Date()) + ".txt";
//
//            FileHelper.writeFile(tmpSubFileName, sb.toString(), "UTF-8");
//        } catch (Exception ex) {
//            ex.printStackTrace();
//            WriteBankLogLn2(ex.getMessage());
//        } finally {
//            isWorking = false;
//            if (sftpPortClient != null) {
//                try {
//                    sftpPortClient.disconnect();
//                } catch(IOException ex) {
//                    ex.printStackTrace();
//                    WriteBankLogLn2(ex.getMessage());
//                }
//            }
//        }
//    }
//
//    @Override
//    public void run() {
//        pushReceipt();
//    }
//}